home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0493 / TIMEFORM.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-29  |  1KB  |  27 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 663 of 702
  3. From : MIKE COPELAND                       1:114/151.0          21 Apr 93  22:13
  4. To   : JON RUPERT
  5. Subj : SECONDS TO H:M:S
  6. ────────────────────────────────────────────────────────────────────────────────
  7.  JR> I'm looking for some FAST routines to change seconds into a
  8.  JR> readable format, (ie. H:M:S).
  9.  
  10.  JR> For instance, 8071 seconds = 2:14:31
  11.  
  12.    Here's the code I use, and it's fast enough for me: }
  13.  
  14. function FORMAT_TIME (V : integer) : STR8; { format time as hh:mm:ss }
  15. var X,Z   : integer;
  16.     PTIME : STR8;
  17. begin                            { note: incoming time is in seconds }
  18.   Z := ord('0'); PTIME := '  :  :  ';                   { initialize }
  19.   X := V div 3600; V := V mod 3600;                  { process hours }
  20.   if (X > 0) and (X <= 9) then PTIME[2] := chr(X+Z)
  21.   else if X = 0 then PTIME[3] := ' '                 { zero-suppress }
  22.        else          PTIME[2] := '*';                  { overflow... }
  23.   X := V div 60; V := V mod 60;                    { process minutes }
  24.   PTIME[4] := chr((X div 10)+Z); PTIME[5] := chr((X mod 10)+Z);
  25.   PTIME[7] := chr((V div 10)+Z);                   { process seconds }
  26.   PTIME[8] := chr((V mod 10)+Z); FORMAT_TIME := PTIME
  27. end;  { FORMAT_TIME }